home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-07-10 | 18.4 KB | 483 lines | [TEXT/MPS ] |
- {
- COPYRIGHT (C) 1984-1990 Apple Computer,Inc.
- All rights reserved
-
- Resource editor interface unit for instances of editors and pickers. This should be
- USE'd by any pascal implementation of a resource editor or picker. The
- companion file ResDisp.a.o should be linked with the pascal to build
- the file for inclusion in ResEdit.
-
- Pickers are given a resource type and should display all of that type in
- the current resfile in a suitable format. If the picker is given an open call
- AND there's a compatible editor, it should give birth to the Editor. The editor
- is given a handle to the resource object and it should open up an edit
- window for the user.
-
- }
-
-
- UNIT ResEd;
-
-
- INTERFACE
-
- Uses Memtypes, QuickDraw, OSIntf, ToolIntf, Printing;
-
-
- CONST
-
- { Standard menus exported by ResEdit }
-
- fileMenu = 2;
-
- newFileItem = 1;
- openFileItem = 2;
- openSpecialItem = 3;
- closeItem = 4;
- saveItem = 5;
- revertItem = 6;
- getThisInfoItem = 8;
- getInfoItem = 9;
- verifyItem = 10;
- pageSetupItem = 12;
- printItem = 13;
- preferencesItem = 15;
- quitItem = 17;
-
- { Masks for AbleMenu - normally not used directly. }
- newFileMask = $2;
- openFileMask = $4;
- openSpecialMask = $8;
- closeMask = $10;
- saveMask = $20;
- revertMask = $40;
- getThisInfoMask = $100;
- getInfoMask = $200;
- verifyMask = $400;
- pageSetupMask = $1000;
- printMask = $2000;
- preferencesMask = $08000;
- quitMask = $020000;
- disabledMask = $1;
-
- { Mask combinations to be used in calls to AbleMenu. }
- fileNotOpen = disabledMask + newFileMask + openFileMask + openSpecialMask + getInfoMask +
- verifyMask + pageSetupMask + preferencesMask + quitMask;
- fileNoPrint = fileNotOpen + getThisInfoMask + closeMask + saveMask + revertMask;
- fileAll = fileNoPrint + printMask;
- fileNoSaveOrRevert = fileNotOpen + getThisInfoMask + closeMask + printMask;
- fileDA = disabledMask + openFileMask + newFileMask + openSpecialMask +
- getInfoMask + verifyMask + closeMask + quitMask;
-
- rsrcMenu = 128;
-
- rsrcCreateItem = 1;
- rsrcOpenItem = 2;
- rsrcOpenTemplateItem= 3;
- rsrcOpenHexItem = 4;
- rsrcRevertItem = 6;
- rsrcGetInfoItem = 8;
-
- rsrcCreateMask = $2;
- rsrcOpenMask = $4;
- rsrcOpenTemplateMask= $8;
- rsrcOpenHexMask = $10;
- rsrcRevertMask = $40;
- rsrcGetInfoMask = $100;
- rsrcDisabledMask = $FFFFFE01;
-
- rsrcDisabled = $FFFFFE00;
- rsrcRevertOnly = rsrcDisabledMask + rsrcRevertMask;
- rsrcPickerNoSel = rsrcDisabledMask + rsrcCreateMask;
- rsrcFilePicker = rsrcPickerNoSel + rsrcOpenHexMask + rsrcRevertMask + rsrcOpenMask;
- rsrcRsrcPicker = rsrcFilePicker + rsrcOpenTemplateMask + rsrcGetInfoMask;
- rsrcEditor = rsrcDisabledMask + rsrcRevertMask + rsrcGetInfoMask;
- rsrcEditorPicker = rsrcEditor + rsrcOpenMask + rsrcOpenTemplateMask + rsrcOpenHexMask;
- rsrcDITLEd = rsrcEditorPicker - rsrcOpenHexMask + rsrcCreateMask;
- rsrcEditorCreate = rsrcEditor + rsrcCreateMask;
-
- editMenu = 3;
-
- undoItem = 1;
- cutItem = 3;
- copyItem = 4;
- pasteItem = 5;
- clearItem = 6;
- dupItem = 8;
- selectAllItem = 9;
- selectChangedItem =10;
-
- { Masks for AbleMenu - normally not used directly. }
- undoMask = $2;
- cutMask = $8;
- editCopyMask = $10;
- pasteMask = $20;
- clearMask = $40;
- duplicateMask = $100;
- selectAllMask = $200;
- selectChangedMask=$400;
- editDisabledMask= $FFFFF801;
-
- { Mask combinations to be used in calls to AbleMenu. }
- editNone = editDisabledMask - 1;
- editClear = editDisabledMask + clearMask;
- editCopy = editDisabledMask + editCopyMask;
- editPaste = editDisabledMask + pasteMask;
- editUndoPasteOnly = editPaste + undoMask;
- editDup = editClear + duplicateMask;
- editNoDup = editDisabledMask + cutMask + editCopyMask + pasteMask + clearMask; { No dup or undo }
- editNoUndo = editNoDup + duplicateMask;
- editUndNoDup= editNoDup + undoMask;
- editAll = editNoUndo + undoMask;
- editAcc = editUndNoDup; { for DAs }
-
- viewMenu = 130; { Type pickers view menu. }
-
- viewByIDItem = 1;
- viewByNameItem = 2;
- viewBySizeItem = 3;
- viewByOrderItem = 4;
- viewBySpecialItem = 5;
- viewShowAttributesItem = 7;
-
- { Masks for AbleMenu. }
- viewByIDMask = $2;
- viewByNameMask = $4;
- viewBySizeMask = $8;
- viewByOrderMask = $10;
- viewBySpecialMask = $20;
- viewShowAttributesMask = $80;
- viewDisabledMask = $FFFFFF01;
-
- viewNoSpecial = viewDisabledMask + viewByIDMask + viewByNameMask + viewBySizeMask + viewByOrderMask + viewShowAttributesMask;
- viewNoAttributes = viewDisabledMask + viewByIDMask + viewByNameMask + viewBySizeMask + viewByOrderMask + viewBySpecialMask;
- viewAll = viewNoAttributes + viewShowAttributesMask;
-
- fontMenu = 144; { Font menu with menus already added. }
-
- miscStrings = 129; { Resource ID of STR# resource containing the strings. }
- miscStringsName = 'Misc'; { Accessing resources by name is preferred }
- cantLoadSndErrStr = 24; { Snd picker string. }
- sysStr = 45; { 'Sys', etc. used by LDEF. }
-
- { Text for selected errors }
- errorStrings = 132; { Resource ID of STR# resource containing the error strings }
- errorStringsName = 'Errors'; { Accessing resources by name is preferred }
- genericErrStr = 1; { Returned by GetErrorText when no specific message available }
- ioErrStr = 1;
- writeProtectErrStr = 2;
- diskFullErrStr = 3;
- fileLockedErrStr = 4;
- outOfMemoryErrStr = 5;
- alreadyOpenErrStr = 6;
- tooManyOpenErrStr = 7;
- volNotMountedErrStr = 8;
- resNotFoundErrStr = 9;
- accessErrStr = 10;
- resFileNotFoundErrStr = 11;
- addResFailErrStr = 12;
- removeResFailErrStr = 13;
- resAttributesErrStr = 14;
- resMapErrStr = 15;
- fileNotFoundErrStr = 16;
- eofErrStr = 17;
- fileBusyStr = 18;
- cantDecompressStr = 19;
-
- arrowCursor = -1; { Used in the call to SetTheCursor to set the arrow cursor. }
-
- theScrollBar = 15; { Width of a scroll bar. }
-
- okChoice = 1; { Used for the OK button in dialogs. }
-
- noDialog = 0; { Used with EditorWindSetup. }
- noScrap = -1; { Used with GetResEditScrapFile. }
-
- alertStringsName = 'Alert strings';
- revertResourceAlertStr = 1;
- noTemplateAlert = 2; { GNRL editor }
- cantPlayOnThisMachineAlert = 3; { snd picker }
- cantPlaySndAlert = 4; { snd picker }
-
- { Consts for Resource menu string }
- rsrcStrName = 'Resource menu';
- rsrcCreateStr = 1;
- rsrcOpenStr = 2;
- rsrcListStr = 3;
- rsrcOpenLists = 4;
- rsrcOpenEditor = 5;
- rsrcOpenEditors = 6;
- rsrcOpenHex = 7;
- rsrcRevert = 8;
- rsrcRevertThese = 9;
- rsrcResources = 10;
- rsrcRevertRes = 11;
- rsrcRevertThis = 12;
- rsrcPatCreateStr = 13;
- rsrcSICNCreateStr = 14;
- rsrcDITLCreateStr = 15;
- rsrcRevertItemStr = 16;
- rsrcGNRLCreateStr = 17;
- rsrcOpenTemplate = 18;
- rsrcOpenPickerByID = 19;
-
- { Character code constants }
- leftArrowKey = $1c;
- rightArrowKey = $1d;
- upArrowKey = $1e;
- downArrowKey = $1f;
- tabkey = $09;
- enterKey = $03;
- deleteKey = $08;
- returnKey = $0d;
- escapeKey = $1b;
- periodKey = $2e;
-
- TYPE
- STR64 = STRING[64];
-
- { Alert kinds used by the DisplayAlert procedure. }
- AlertType = (displayTheAlert, displayStopAlert, displayNoteAlert, displayCautionAlert,
- displayYNAlert, displayYNCAlert, displayYNCStopAlert, displayCancelDefaultCautionAlert);
-
- { Icon kinds used by the ChooseIcon function }
- IconType = ( noIcon, normalIcon, reducedIcon, smallIcon, onlyICON, onlyICNPound );
- { This defines the various types of icons handled by the icon chooser package.
- Passing onlyICON in the IconKind parameter of the ChooseIcon function forces the
- IconChooser to not allow reduced ICONs and SICNs. Passing onlyICNPound in
- the IconKind parameter uses ICN# resources instead of ICONs. Passing any
- other value instructs the IconChooser to support regular ICONs, reduced ICONs,
- and SICNs (like in the MENU editor). }
-
- { Kinds of windows that support color in different degrees }
- ColorType = ( noColor, canColor, requiresColor );
-
- { This structure is used by the GetQuickDrawVars procedure. }
- pQuickDrawVars = ^QuickDrawVars;
- QuickDrawVArs = RECORD
- randSeed: LONGINT;
- screenBits: BitMap;
- arrow: Cursor;
- dkGray: Pattern;
- ltGray: Pattern;
- gray: Pattern;
- black: Pattern;
- white: Pattern;
- thePort: GrafPtr;
- END; { QuickDrawVars }
-
- PickerType = (textOnlyPicker, graphical1DPicker, graphical2DPicker);
-
- PossibleWindowTypes = (typePickerWindow, resourcePickerWindow,
- folderInfoWindow, fileInfoWindow, resourceInfoWindow,
- editorWindow, floatingWindow);
- ParentPtr = ^ParentRec;
- ParentHandle = ^ParentPtr;
-
- ParentRec = RECORD
- father: ParentHandle;
- name: str255;
- wind: WindowPeek; { Window that this record belongs to. }
- rebuild: BOOLEAN; { Flag set to indicate that window should be rebuilt }
- resWasntLoaded: BOOLEAN; { TRUE if the resource should be released when the window is closed. }
- windowType: PossibleWindowTypes;
- theResType: ResType; { Type of the resource being picked or edited. }
- theResFile: INTEGER; { The home resfile of the window. }
- codeResID: INTEGER; { Resource ID of the RSSC resource containing the picker or editor. }
- theResToEdit: Handle;
- END;
-
- { Standard picker record }
-
- PickPtr = ^PickRec;
- PickHandle = ^PickPtr;
-
- ViewTypes = (viewById, viewByName, viewBySize, viewByOrder, viewBySpecial);
- PickRec = RECORD
- father: ParentHandle; { Back ptr to dad }
- fName: STR255;
- wind: WindowPtr; { Picker window }
- rebuild: BOOLEAN;
- spare1: BOOLEAN; { Not used here}
- windowType: PossibleWindowTypes;
- theResType: ResType; { Type of the resource being picked or edited. }
- theResFile: INTEGER; { The home resfile of the window. }
- codeResID: INTEGER; { Resource ID of the RSSC resource containing the picker or editor. }
- spare: Handle; { Not used here}
-
- rType: ResType; { Type for picker - could be different from theResType }
- rSize: LONGINT; { Size of a null resource }
- minWindowWidth: INTEGER; { Used when the window is grown. }
- minWindowHeight:INTEGER;
- instances: ListHandle; { List of instances }
- nInsts: INTEGER; { Number of instances }
- viewBy: ViewTypes; { Current view type }
- showAttributes: BOOLEAN; { Show attrs in window? }
- ldefType: ResType; { Which LDEF to use }
- theViewMenu: MenuHandle; { The picker view menu }
- viewMenuMask: LONGINT; { Which items are enabled? }
- cellSize: Cell; { Cell size for special view. }
- optionCreateStr:STR255; { Create item menu text when the option key is pressed. }
- END;
-
- FloatingWindowPtr = ^FloatingWindowRec;
- FloatingWindowHandle = ^FloatingWindowPtr;
- FloatingWindowRec = RECORD
- father: ParentHandle; { Back ptr to dad }
- name: STR255;
- wind: WindowPtr; { Floating window. }
- rebuild: BOOLEAN;
- visible: BOOLEAN; { Is the window to be hidden temporarily }
- windowType: PossibleWindowTypes;
- theResType: ResType; { Type of the resource being picked or edited. }
- theResFile: INTEGER; { The home resfile of the window. }
- codeResID: INTEGER; { Resource ID of the RSSC resource containing the picker or editor. }
- ownerWindow: WindowPtr; { Which window owns this floating window? }
- END;
-
-
- { Window Utilities }
-
- FUNCTION AlreadyOpen (VAR windowTitle, windowName: STR255; father: ParentHandle): BOOLEAN;
- FUNCTION EditorWindSetup (dlogID: INTEGER; colorKind: ColorType; width, height: INTEGER;
- VAR windowTitle, windowName: STR255; addFrom: BOOLEAN;
- windowKind: INTEGER; father: ParentHandle): WindowPtr;
- FUNCTION FloatingWindowSetup (WINDID: INTEGER; fw: FloatingWindowHandle;
- owner: Parenthandle; where: Point): WindowPtr;
- PROCEDURE GetWindowTitle (VAR windowTitle, windowName: STR255; addFrom: BOOLEAN; father: ParentHandle);
- FUNCTION PickerWindSetup(colorKind: ColorType; showTheWindow: BOOLEAN; width, height: INTEGER; VAR windowTitle: STR255;
- windowKind: INTEGER; dad: ParentHandle): WindowPtr;
- PROCEDURE SetETitle (h: Handle; VAR str: STR255);
- FUNCTION WindAlloc: WindowPtr;
- PROCEDURE WindReturn (w: WindowPtr);
-
- { Extended Resource Manager. }
-
- FUNCTION REAddNewRes(resFile: INTEGER; hNew: Handle; t: ResType; idNew: INTEGER; s: STR255): BOOLEAN;
- PROCEDURE REAddResource(resFile: INTEGER; theResource: Handle;
- theType: ResType;theID: INTEGER; name: Str255);
- FUNCTION REBeautifulUnique1ID(resFile: INTEGER; WhichType: ResType): INTEGER;
- FUNCTION RECount1Resources(resFile: INTEGER; theType: ResType): INTEGER;
- FUNCTION RECount1Types (resFile: INTEGER): INTEGER;
- FUNCTION REGet1IndResource(resFile: INTEGER; theType: ResType;index: INTEGER): Handle;
- PROCEDURE REGet1IndType(resFile: INTEGER; VAR theType: ResType;index: INTEGER);
- FUNCTION REGet1NamedResource(resFile: INTEGER; theType: ResType;name: Str255): Handle;
- FUNCTION REGet1Resource(resFile: INTEGER; theType: ResType;theID: INTEGER): Handle;
- FUNCTION REGet1ResourceSpecial (resFile: INTEGER; theType: ResType; ID: INTEGER;
- VAR wasLoaded: BOOLEAN; VAR error: INTEGER): Handle;
- FUNCTION RENewUniqueRes(resFile: INTEGER; s: LONGINT; t: ResType): Handle;
- PROCEDURE RERemoveAnyResource (resFile: INTEGER; theRes: Handle);
- FUNCTION RevertThisResource (theObj: ParentHandle; res: Handle): BOOLEAN;
-
- { Routines used by pickers. }
-
- FUNCTION DefaultListCellSize:INTEGER;
- FUNCTION DoPickBirth(colorKind: ColorType; buildList: BOOLEAN; which: PickerType;
- pickerResId: INTEGER; pick: PickHandle): BOOLEAN;
-
- { The drawProc is of the form: PROCEDURE DrawResource (lRect: Rect; theRes: Handle); }
- PROCEDURE DrawLDEF (message: INTEGER; lSelect: BOOLEAN; lRect: Rect; theRes: Handle;
- id: INTEGER; title: STR255; maxH, maxV: INTEGER;
- DrawResource: ProcPtr; lh: ListHandle);
- PROCEDURE GrowMyWindow (minWidth, minHeight: INTEGER; windPtr: WindowPtr; lh: ListHandle);
- PROCEDURE PickEvent (VAR evt: EventRecord; pick: PickHandle);
- PROCEDURE PickInfoUp (oldID, newID: INTEGER; pick: PickHandle);
- PROCEDURE PickMenu (menu, item: INTEGER; pick: PickHandle);
- FUNCTION PickStdHeight: INTEGER;
- FUNCTION PickStdWidth: INTEGER;
-
- { Routines used by editors. }
- FUNCTION CloseNoSave: BOOLEAN;
- FUNCTION NeedToRevert (myWindow: WindowPtr; theRes: Handle): BOOLEAN;
- PROCEDURE NoDoubleClickHere;
- PROCEDURE SetResChanged (h: Handle);
- FUNCTION WasItLoaded: BOOLEAN;
-
- { Routines used to start pickers and editors. }
-
- PROCEDURE GiveEBirth (resHandle: Handle; pick: PickHandle);
- PROCEDURE GiveSubEBirth (resHandle: Handle; pick: PickHandle);
- PROCEDURE GiveThisEBirth (resHandle: Handle; pick: PickHandle; openThisType:ResType);
-
- { Routines used to feed events and menus to the appropriate picker or editor. }
-
- PROCEDURE CallDoEvent (evt: EventRecord; theWindow: WindowPtr);
- PROCEDURE CallInfoUpdate (oldID, newID: INTEGER; refcon: LONGINT; id: INTEGER );
- PROCEDURE PassEvent (evt: EventRecord; father: ParentHandle);
- PROCEDURE PassMenu (menu, item: INTEGER; father: ParentHandle);
-
- { Miscellaneous utilities. }
-
- PROCEDURE Abort;
- PROCEDURE AbleMenu(menu: INTEGER; enable: LONGINT);
- PROCEDURE BubbleUp(h: Handle);
- PROCEDURE CenterDialog(theType: ResType; dialog: INTEGER);
- FUNCTION CheckError(err, msgID: INTEGER): BOOLEAN;
- FUNCTION ChooseIcon( EdHandle: ParentHandle; VAR IconResID: integer;
- VAR IconKind: IconType; dialogID: integer): BOOLEAN;
- FUNCTION ColorAvailable(needColorQD: BOOLEAN): BOOLEAN;
- PROCEDURE ConcatStr(VAR str1: STR255; str2: STR255);
- FUNCTION DisplayAlert(which: AlertType; id: INTEGER): INTEGER;
- FUNCTION DisplaySTRAlert(which: AlertType; STRName: STR255; STRIndex: INTEGER): BOOLEAN;
- PROCEDURE DrawMBarLater(forceItNow: BOOLEAN);
- FUNCTION FindOwnerWindow(theRes: Handle): WindowPeek;
- PROCEDURE FixHand(s: LONGINT; h: Handle);
- PROCEDURE FlashDialogItem(dp: DialogPtr; item: integer);
- PROCEDURE FrameDialogItem(dp: DialogPtr; item: integer);
- PROCEDURE GetNamedStr(index: INTEGER; name: STR255; VAR str: STR255);
- FUNCTION GetQuickDrawVars: pQuickDrawVars;
- FUNCTION GetScreenRect(roomForIcons: BOOLEAN; wind: WindowPtr): Rect;
- PROCEDURE GetStr(index, resID: INTEGER; VAR str: STR255);
- FUNCTION HandleCheck(h: Handle; msgID: INTEGER): BOOLEAN;
- PROCEDURE MetaKeys(VAR cmd, shift, opt: BOOLEAN);
- FUNCTION PrintSetup: Handle; { Return type is actually THPrint }
- PROCEDURE PrintWindow(toPrint: PicHandle);
- FUNCTION ResEdID: INTEGER;
- PROCEDURE SetTheCursor(whichCursor: INTEGER);
- PROCEDURE ShowInfo(h:Handle; father: ParentHandle);
- FUNCTION StandardFilter(theDialog: DialogPtr; VAR theEvent: EventRecord;
- VAR itemHit: INTEGER): BOOLEAN;
- PROCEDURE TypeToString(t: ResType; VAR s: Str255);
- PROCEDURE UseAppRes;
- FUNCTION WasAborted: BOOLEAN;
-
- { Popup Menus }
-
- FUNCTION ColorPalettePopupSelect(whichWindow: WindowPtr; itemBox: Rect;
- VAR whichColor: RGBColor; CQDishere: Boolean; useColorPicker: BOOLEAN ): Boolean;
- PROCEDURE DeinstallColorPalettePopup(whichWindow: WindowPtr; CQDishere: Boolean );
- PROCEDURE DoPopup( whichDialog: DialogPtr; promptDialogItem, popupDialogItem: integer;
- VAR menuItem: integer; whichMenu: MenuHandle);
- PROCEDURE DrawColorPopup(whichWindow: WindowPtr; itemBox: Rect;
- whichColor: RGBColor; CQDishere: Boolean );
- PROCEDURE DrawPopup( whichDialog: DialogPtr; whichDialogItem, whichMenuItem: integer;
- whichMenu: MenuHandle);
- PROCEDURE InstallColorPalettePopup(whichWindow: WindowPtr; CQDishere, isActive: Boolean );
-
- { Routines that are used internally within ResEdit and may be useful in other
- circumstances. }
-
- FUNCTION BuildType (t: ResType; l: ListHandle): INTEGER;
- FUNCTION CompressedResource(theResource: Handle): BOOLEAN;
- PROCEDURE DoKeyScan (var evt: EventRecord; offset: integer; lh: ListHandle);
- FUNCTION DupPick (h: Handle; c: cell; pick: PickHandle): Handle;
- PROCEDURE GetErrorText (error: INTEGER; VAR errorText: STR255);
- FUNCTION GetResEditScrapFile: INTEGER;
- FUNCTION GetType (templatesOnly: BOOLEAN; VAR s: STR255): BOOLEAN;
- FUNCTION MapResourceType (editor: BOOLEAN; theRes: Handle; origResType: ResType): ResType;
- FUNCTION PlaySyncSound(which: INTEGER; sndHandle: Handle): BOOLEAN;
- FUNCTION ResEditRes: INTEGER;
- Inline { move.w CurApRefNum,(sp) } $3eB8, $0900;
- PROCEDURE ResourceIDHasChanged (theObj: ParentHandle; theType: ResType; theOldId, theNewId: INTEGER);
- FUNCTION RestoreRemovedResources (pick: PickHandle): BOOLEAN;
- PROCEDURE ScrapCopy (theType: ResType; VAR h: Handle);
- PROCEDURE ScrapEmpty;
- PROCEDURE SendRebuildToPicker (theType: ResType; parent: ParentHandle);
- PROCEDURE SendRebuildToPickerAndFile (theType: ResType; parent: ParentHandle) ;
- FUNCTION SysResFile: INTEGER;
- FUNCTION WindList (w: WindowPtr; nAcross: INTEGER; cSize: Point; drawProc:INTEGER): ListHandle;
- PROCEDURE WindOrigin (w: WindowPtr; dad: ParentHandle);
- PROCEDURE WritePreferences (prefType: ResType; prefId: INTEGER; prefName: STR255; prefHandle: Handle);
-
- END.
-